package com.ljtxxhwj.myblob.controller;

import com.ljtxxhwj.myblob.entity.Subscribe;
import com.ljtxxhwj.myblob.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/subscribe")
public class SubscribeController {
    @Autowired
    SubscribeService subscribeService;

    @GetMapping("/getSubscribed.do")
    public List<Subscribe> getSubscribed(@RequestParam("userId") int userId){
        return subscribeService.getSubscribed(userId);
    }

    @PostMapping("/subscribeToSomeone.do")
    public String subscribeToSomeone(@RequestBody Subscribe subscribe){
        Timestamp subscribeDate = new Timestamp(new Date().getTime());
        subscribe.setSubsribeDate(subscribeDate);
        subscribeService.subscribeToSomeone(subscribe);
        return "{ subscribeToSomeone : success}";
    }
}
